package RevolCraft.Blocks;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;

import cpw.mods.fml.common.Side;
import cpw.mods.fml.common.asm.SideOnly;
import cpw.mods.fml.common.network.PacketDispatcher;
import cpw.mods.fml.common.network.Player;
import RevolCraft.Common.ClientProxy;
import RevolCraft.TileEntities.TileEntityElectricFurnace;
import RevolCraft.TileEntities.TileEntityGenerator;
import net.minecraft.src.Block;
import net.minecraft.src.CreativeTabs;
import net.minecraft.src.EntityLiving;
import net.minecraft.src.IBlockAccess;
import net.minecraft.src.Material;
import net.minecraft.src.MathHelper;
import net.minecraft.src.Packet250CustomPayload;
import net.minecraft.src.TileEntity;
import net.minecraft.src.World;

public class BlockElectricFurnace extends BlockMachine
{
	public BlockElectricFurnace(int id, int icon)
	{
		super(id, icon, Material.iron);
		this.setCreativeTab(CreativeTabs.tabMisc);
		this.setBlockName("Electric Furnace");
		this.setHardness(1.f);
		this.setResistance(10.f);
		this.setStepSound(Block.soundMetalFootstep);
		this.setTextureFile("/RevolCraft/Resources/ElectricFurnaceOn.png");
	}

	@Override
	public void buildAndSendPacket(TileEntity tileEntity, Player player) {
		TileEntityElectricFurnace te = (TileEntityElectricFurnace) tileEntity;
        
        ByteArrayOutputStream bos = new ByteArrayOutputStream(25);
        DataOutputStream outputStream = new DataOutputStream(bos);
        try {
        	outputStream.write(1);
        	outputStream.writeInt(te.xCoord);
        	outputStream.writeInt(te.yCoord);
        	outputStream.writeInt(te.zCoord);
        	outputStream.writeInt(te.cookTime);
        	outputStream.writeInt(te.currentStorage);
        	outputStream.writeInt(te.maxStorage);
        } catch (Exception ex) {
        	ex.printStackTrace();
        }
        Packet250CustomPayload packet = new Packet250CustomPayload();
        packet.channel = "TileEntities";
        packet.data = bos.toByteArray();
        packet.length = bos.size();
        
        PacketDispatcher.sendPacketToPlayer(packet, player);
		
	}

	@Override
	public TileEntity createTileEntity(World world, int metadata) {
		return new TileEntityElectricFurnace();
	}

	@Override
	public TileEntity createNewTileEntity(World var1) {
		return new TileEntityElectricFurnace();
	}
}
